package com.study.ju.web;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

/**
 * <p>Filter测试</p>
 *
 * @version v 0.1 2023/4/10 20:09
 */
public class FilterTest implements Filter {
    protected FilterConfig filterConfig;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
        //xml配置中获取参数
        String illegal_char_check = filterConfig.getInitParameter("illegal_char_check");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("before...");
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("after...");
    }

    @Override
    public void destroy() {
        filterConfig = null;
    }
}
